package com.meng.baselibrary.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2017/5/11.
 */

public abstract class BaseLazyLoadFragment extends Fragment {
    protected View contentView;
    protected Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = inflater.inflate(getContentViewLayout(),null);
        initView();
        return contentView;
    }
    protected abstract int getContentViewLayout();
    protected <T extends View> T findViewById(int id){
        return (T) contentView.findViewById(id);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }
    protected abstract void initData();
    protected abstract void initView();
    protected boolean isInitData;
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser && !isInitData){
            initData();
            isInitData = true;
        }
    }
}
